# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=ruby-rdiscount
_gemname=rdiscount
pkgver=2.2.0.1
pkgrel=5
pkgdesc="Fast Implementation of Gruber's Markdown in C"
url="http://dafoster.net/projects/rdiscount/"
arch="all"
license="BSD-3-Clause"
checkdepends="perl ruby-test-unit tidyhtml"
makedepends="ruby-dev ruby-rake"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/davidfstr/$_gemname/archive/$pkgver.tar.gz
	fix-rakefile.patch"
builddir="$srcdir/$_gemname-$pkgver"

build() {
	cd "$builddir"

	gem build $_gemname.gemspec
	gem install --local \
		--install-dir dist \
		--ignore-dependencies \
		--no-document \
		--verbose \
		$_gemname
}

check() {
	cd "$builddir"
	rake test
}

package() {
	local gemdir="$pkgdir/$(ruby -e 'puts Gem.default_dir')"
	cd "$builddir"/dist

	mkdir -p "$gemdir"
	cp -r extensions gems specifications "$gemdir"/

	install -D -m 755 bin/$_gemname "$pkgdir"/usr/bin/$_gemname

	# Remove unnecessary files and rubbish...
	find "$gemdir"/extensions/ -name mkmf.log -delete

	cd "$gemdir"/gems/$_gemname-$pkgver

	_mv man/$_gemname.1 "$pkgdir"/usr/share/man/man1/
	_mv COPYING "$pkgdir"/usr/share/licenses/$pkgname/

	# Remove unnecessary files and rubbish...
	rm -r ext/ lib/*.so man/ test/ Rakefile BUILDING README* || true
}

_mv() {
	local dest; for dest; do true; done  # get last argument
	mkdir -p "$dest"
	mv $@
}

sha512sums="9ed19ce988a6253a15a883047fcf83def23f29efb301507e16ea0402ceded6e67eb13620643063bbae733ad6f98100b79a5a02aefe0a4d5d03969816014e1617  ruby-rdiscount-2.2.0.1.tar.gz
eef24dd1a1bafd0efc27cb7097d5cd26d2ef0daeea2daf57f665d309352561fb79012faf3be2a1e584f735ed3b36ab6dc3fb975c78b8331a38d971b280d75eac  fix-rakefile.patch"
